package com.cardvalue.sys.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;

import com.cardvalue.sys.R;
import com.cardvalue.sys.fragment.HomePageFragment;
import com.cardvalue.sys.fragment.MoreRecylerFragment;
import com.cardvalue.sys.fragment.MyAccountFragment;
import com.cardvalue.sys.tool.TabGroup;

public class HomeActivity extends FragmentActivity {
    private TabGroup tabHost;
    private static final int BACK_EXIT_DURATION = 2000;
    private long exitTime = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        tabHost = (TabGroup) findViewById(R.id.tabhost);
        tabHost.attachContent(R.id.content,HomePageFragment.class,
                MyAccountFragment.class,MoreRecylerFragment.class);//MoreRecylerFragment,MoreFragment
        tabHost.setCurrentView(0);
        if(getIntent().getStringExtra("tagchang")!=null){
            tabHost.setCurrentView(1);
        }

    }

    /** 用户按返回键操作 */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent ke) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && ke.getAction() == KeyEvent.ACTION_DOWN) {

            if (System.currentTimeMillis() - exitTime > BACK_EXIT_DURATION) {
                Toast.makeText(HomeActivity.this, "再按一次退出程序",
                        Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
              //  MyApplication.getInstance().finishAllContext();
            }
            return true;
        }
        return super.onKeyDown(keyCode, ke);
    }
}
